<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>转手商城后台-修改用户</title>
		<link rel="stylesheet" type="text/css" href="../../static/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="../../static/css/admin.css" />

		<script src="../../static/js/public/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/jquery.session.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/axios.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/util.js" type="text/javascript" charset="utf-8"></script>

		<script src="../../static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/common.children.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<div class="page-content-wrap" id="detail">
			<form class="layui-form" @submit.prevent="onSubmit">
				<div class="layui-tab" style="margin: 0;">
					<ul class="layui-tab-title">
						<li><a href="user-list.html">用户列表</a></li>
						<li class="layui-this">用户详情</li>
					</ul>
					<div class="layui-tab-content top-10">
						<div class="layui-tab-item"></div>
						<div class="layui-tab-item layui-show">
							<div class="layui-form-item">
								<label class="layui-form-label">ID：</label>
								<div class="layui-input-block">
									<input type="text" disabled="disabled" v-model="obj.uid" name="uid" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">openID：</label>
								<div class="layui-input-block">
									<input type="text" disabled="disabled" v-model="obj.openid" name="openid" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">qqOpenID：</label>
								<div class="layui-input-block">
									<input type="text" disabled="disabled" v-model="obj.qqopenid" name="qqopenid" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">昵称：</label>
								<div class="layui-input-block">
									<input type="text" v-model="obj.name" name="name" required lay-verify="required" placeholder="请输入昵称" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">电话：</label>
								<div class="layui-input-block">
									<input type="text" v-model="obj.phone" name="phone" placeholder="请输入电话" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">邮箱：</label>
								<div class="layui-input-block">
									<input type="text" v-model="obj.email" name="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">性别：</label>
								<div class="layui-input-block">
									<select name="sex" ref="select" id="select">
										<option value="">请选择性别</option>
										<option v-if="obj.sex != '男'">男</option>
										<option selected="" v-else>男</option>
										<option v-if="obj.sex != '女'">女</option>
										<option selected="" v-else>女</option>
									</select>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">收货地址：</label>
								<div class="layui-input-block">
									<input type="text" v-model="obj.address" name="address" placeholder="请输入收货地址" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">注册时间：</label>
								<div class="layui-input-block">
									<input type="text" disabled="disabled" v-model="obj.registertime" name="registertime" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">密码：</label>
								<div class="layui-input-block">
									<input type="password" v-model="obj.password" name="password" autocomplete="off" class="layui-input">
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="layui-form-item" style="padding-left: 10px;">
					<div class="layui-input-block">
						<button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo" @click="detailSubmit()">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>
		</div>

		<script type="text/javascript">
			var vm = new Vue({
				el: '#detail',
				data: {
					obj:{}
				},
				methods: {
					loadPage() {
						var _this = this;
						axios({
							method: 'get',
							url: getRootURL() + 'admin/select-user',
							params: {
								uid: $.session.get("uid"),
							},
							headers: {
								'Content-Type': 'application/x-www-form-urlencoded',
								'Authorization': $.session.get("token")
							}
						}).then(function(res) {
							console.log(res);
							
							if (res.data.status >= 0) {
								_this.$data.obj = res.data.object;
							} else {
								alert(res.data.msg);
							}
						
						}).catch(function(err) {
							alert(err);
						});
					},
					detailSubmit() {
						var _this = this;
						var optionVal = this.$refs.select.value;
						axios({
							method: 'post',
							url: getRootURL() + 'admin/update-user',
							data: {
								uid: _this.$data.obj.uid,
								name: _this.$data.obj.name,
								phone: _this.$data.obj.phone,
								email: _this.$data.obj.email,
								sex: optionVal,
								address: _this.$data.obj.address,
								password: _this.$data.obj.password
							},
							headers: {
								'Content-Type': 'application/json',
								'Authorization': $.session.get("token")
							}
						}).then(function(res) {
							console.log(res);

							if (res.data.status >= 0) {
								alert(res.data.msg, function() {
									// 刷新页面
									// window.parent.refresh(); //父页面刷新

									// var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
									// parent.layer.close(index); //关闭窗口
								});
							} else {
								alert(res.data.msg);
							}

						}).catch(function(err) {
							alert(err);
						});
					},
					onSubmit() {
						//防止form冒泡
						return false;
					}
				},
				created() {
					this.loadPage()
				}
			})
		</script>
	</body>

</html>
